﻿if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[RemindersQueueGetBySiteCollectionID]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].RemindersQueueGetBySiteCollectionID
GO

CREATE PROCEDURE dbo.RemindersQueueGetBySiteCollectionID
(
	@SiteCollectionID uniqueidentifier
)
AS

SET NOCOUNT ON

SELECT
	*
FROM 
	RemindersQueue
WHERE
	SiteCollectionID = @SiteCollectionID
	AND IsBeingProcessed = 0
	AND Completed = 0 
	
SELECT
	rqi.*
FROM
	RemindersQueueItem rqi INNER JOIN RemindersQueue rq
	ON rqi.RemindersQueueID = rq.RemindersQueueID
WHERE
	rq.SiteCollectionID = @SiteCollectionID
	AND rq.IsBeingProcessed = 0
	AND rq.Completed = 0
GO 